package com.kun.demo01;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

//测试线程创建，下载网络图片
public class ThreadCreate01_test extends Thread {

    String url;
    String fileName;

    public void run(){
        this.downloadPicture(url, fileName);
    }

    public void downloadPicture(String url, String fileName){
        try {
            FileUtils.copyURLToFile(new URL(url), new File(fileName));
            System.out.println("下载图片成功："+fileName);
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("下载图片失败");
        }
    }

    public static void main(String[] args) {
        ThreadCreate01_test test1 = new ThreadCreate01_test();
        test1.url = "https://www.baidu.com/img/bd_logo1.png";
        test1.fileName = "baidu_1.png";
        test1.start();
        ThreadCreate01_test test2 = new ThreadCreate01_test();
        test2.url = "https://www.baidu.com/img/bd_logo1.png";
        test2.fileName = "baidu_2.png";
        test2.start();
        ThreadCreate01_test test3 = new ThreadCreate01_test();
        test3.url = "https://www.baidu.com/img/bd_logo1.png";
        test3.fileName = "baidu_3.png";
        test3.start();
        System.out.println("下载图片结束");
    }





}
